<%@ include file="/common/taglibs.jsp"%>
<%@ page language="java" pageEncoding="utf8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
		<title></title>
		<link rel="stylesheet"
			href="<c:url value="/css/adminsinglepage.css"/>" type="text/css" />
		<link rel="stylesheet"
			href="<c:url value='/scripts/themes/base/jquery.ui.all.css'/>"
			type="text/css" />
	</head>
	<body class="single-page">

		<div id="single-page-tbar">
			<h1>
				<img src="<c:url value="/images/transparent.gif"/>"
					class="imgbundle"
					style="width: 16px; height: 16px; background-position: 0pt -2235px;">
					<strong>订单[${orders.orderId}]发货...操作 
			</h1>

			<ul class="btn-bar">
				<li>
					<button type="button" class="btn btn-quit">
						<span><span>关 闭</span> </span>
					</button>
				</li>
			</ul>
		</div>


		<div class="mainwrap" id="main">
			<div class="spage-main-box">
				<form action="od_ship_save.html" method="post" class="tableform"
					id="ship_form">
					<input type="hidden" value="${orders.orderId}"
						name="orderDelivery.orderId" />
					<input type="hidden" value="1" name="orderDelivery.deliveryType" />

					<input type="hidden" value="${orders.memberId}"
						name="orderDelivery.memberId" />
					<div class="division">
						<table cellspacing="0" cellpadding="0">
							<tbody>
								<tr>
									<th>
										订单号:
									</th>
									<td>
										${orders.orderId}【${orders.shipStatus}】
									</td>
									<th>
										下单日期:
									</th>
									<td>
										${orders.createTimeString}
									</td>
								</tr>
								<tr>
									<th>
										配送方式:
									</th>
									<td>
										<select class="x-input-select  inputstyle"
											onchange='changeCorpStr("orderDelivery_deliveryName",this)'>
											<c:forEach var="type" items="${orderDeliveryTypes}"
												varStatus="index">
												<option value="${type.dtId}">
													${type.dtName}
												</option>
											</c:forEach>
										</select>
										<input type="hidden" name="orderDelivery.deliveryName"
											id="orderDelivery_deliveryName" value="" />
									</td>
									<th>
										配送费用:
									</th>
									<td>
										${orders.costFreight}
									</td>
								</tr>
								<tr>
									<!-- <th>配送地区:</th> <td></td> -->
									<th>
										是否要求保价:
									</th>
									<td colspan="3">
										${orders.protectOn}
									</td>
								</tr>
								<tr>
									<th>
										物流公司:
									</th>
									<td>
										<select
											onchange='changeCorpStr("orderDelivery_logisticsName",this)'
											id="logi_com" name="orderDelivery.logisticsId"
											class="x-input-select  inputstyle">
											<c:forEach var="corp" items="${orderDeliveryCorps}"
												varStatus="index">
												<option value="${corp.corpId}">
													${corp.corpName}
												</option>
											</c:forEach>
										</select>

										<input type="hidden" value=""
											name="orderDelivery.logisticsName"
											id="orderDelivery_logisticsName" />

									</td>
									<th>
										物流单号:
									</th>
									<td>
										<input type="text" name="orderDelivery.logisticsNo"
											class="x-input " />
									</td>
								</tr>
								<tr>
									<th>
										物流费用:
									</th>
									<td>
										<input type="text" value="${orders.costFreight}"
											name="orderDelivery.money" class="x-input " />
									</td>
									<th>
										物流保价:
									</th>
									<td>
										<input type="radio" checked="checked" value="0"
											name="orderDelivery.protectedFlag" />

										<label>
											否
										</label>
										<input type="radio" value="1"
											name="orderDelivery.protectedFlag" />
										<label>
											是
										</label>
									</td>
								</tr>
								<tr>
									<th>
										保价费用:
									</th>
									<td colspan="3">
										${orders.costProtect }
									</td>
								</tr>
								<tr>
									<th>
										收货人姓名:
									</th>
									<td>
										<input type="text" value='${orders.shipName}'
											name="orderDelivery.shipName" class="x-input " />
									</td>
									<th>
										电话:
									</th>
									<td>
										<input width="150" type="text" value='${orders.shipTel}'
											name="orderDelivery.shipTel" class="x-input " />
									</td>
								</tr>
								<tr>
									<th>
										手机:
									</th>
									<td>
										<input type="text" value='${orders.shipMobile}'
											name="orderDelivery.shipMobile" class="x-input " />
									</td>
									<th>
										邮政编码:
									</th>
									<td>
										<input type="text" value='${orders.shipZip}'
											name="orderDelivery.shipZip" class="x-input " />
									</td>
								</tr>
								<tr>
									<th>
										地区:
									</th>
									<td colspan="3">
										<input type="hidden" name="orderDelivery.shipArea"
											id="orderDelivery_shipArea" oldvalue="${orders.shipArea}"
											value="${orders.shipArea}">
											<select id="dl_province"
												onchange="findSubRegions(this,'dl_city','dl_province_hidden'); ">
												<c:forEach var="region" items="${systemRegionses}">
													<option value="${region.regionId}"
														<c:if test="${region.localName eq orders.province }">selected="selected"</c:if>>
														${region.localName}
													</option>
												</c:forEach>
											</select>

											<select id="dl_city"
												onchange="findSubRegions(this,'dl_area','dl_city_hidden')">
												<option value="">
													<c:if test="${empty orders.city}">请选择...</c:if>
													<c:if test="${not empty orders.city}">${orders.city}</c:if>
												</option>
											</select>
											<select id="dl_area" onchange="changeStr(this)">
												<option value="">
													<c:if test="${empty orders.district}">请选择...</c:if>
													<c:if test="${not empty orders.district}">${orders.district}</c:if>
												</option>
											</select>
									</td>
								</tr>
								<tr>
									<th>
										地址:
									</th>
									<td colspan="3">
										<input type="text" style="width: 360px;"
											value="${orders.shipAddr }" name="orderDelivery.shipAddr"
											class="x-input " />
									</td>
								</tr>
								<tr>
									<th>
										发货单备注:
									</th>
									<td colspan="3">
										<textarea style="width: 95%;"
											name="orderDelivery.deliveryDescription"></textarea>
									</td>
								</tr>
							</tbody>
						</table>
					</div>
					<div class="division">
						<table cellspacing="0" cellpadding="0" class="gridlist">

							<thead>
								<tr>
									<th>
										货号
									</th>
									<th>
										商品名称
									</th>
									<th>
										当前库存
									</th>
									<th>
										购买数量
									</th>
									<th>
										已发货
									</th>
									<th>
										此单发货
									</th>
								</tr>
							</thead>
							<tbody>
								<c:forEach items="${orderItems}" var="item" varStatus="index">
									<tr>
										<td>
											${item.bn }
										</td>
										<td>
											${item.name}
										</td>
										<td>
											${item.store}
										</td>
										<td>
											${item.productCount}
										</td>
										<td>
											${item.sendCount}
										</td>
										<td>
											<input type="text"
												value="${item.productCount-item.sendCount}"
												name="orderDeliveryItems[${index.index}].productCount"
												class="x-input {required:true,number:true,max:${item.productCount-item.sendCount},min:0,  messages:{required:'必填 字段',number:'请输入数字',max:'最大为{0}',min:'最小为{0}'} }" />
											<input type="hidden" value="${item.bn }"
												name="orderDeliveryItems[${index.index}].productBn" />
											<input type="hidden" value="${item.name}"
												name="orderDeliveryItems[${index.index}].productName" />
											<input type="hidden" value="1"
												name="orderDeliveryItems[${index.index}].itemType" />
											<input type="hidden" value="${item.productId}"
												name="orderDeliveryItems[${index.index}].productId" />
											<input type="hidden" value="${item.itemId}"
												name="orderDeliveryItems[${index.index}].orderItemId" />
											
										</td>
									</tr>
								</c:forEach>
							</tbody>
						</table>
					</div>
					<div class="table-action">
						<button class="btn" type="submit">
							<span><span>发货</span> </span>
						</button>
					</div>
				</form>
			</div>



		</div>

		<div class="footBar" id="footBar">
		</div>


		<script type="text/javascript"
			src="<c:url value='/scripts/jquery-1.4.2.js'/>"></script>
		<script type="text/javascript"
			src="<c:url value='/scripts/jquery.validate.js'/>"></script>
		<script type="text/javascript"
			src="<c:url value='/scripts/jquery.metadata.js'/>"></script>

		<%@ include file="/jsp/admin/common/messages.jsp"%>

		<script type="text/javascript">
	function autoHeightAndWeight() {
		$("#main").height($("body").height() - $("#single-page-tbar").height());

	}

	autoHeightAndWeight();
	
	
	function findSubRegions(obj,subId,hiddenId) {
		var url = "<c:url value="/sys_region_list.html" />";  
		var regionId = $(obj).attr('value'); 
		if(regionId==''){
			return;
		}
		$('#dl_area').html('');
		$('#dl_area').html('<option value="">请选择...	</option>');
		var text = $(obj).find("option:selected").text().trim();
		$('#'+hiddenId).attr('value',text); 
		 
		var params = {
			"regionId" : regionId
		};

		$.getJSON(url, params, function callback(data) {
			 var regions = data.systemRegionss;
			 $('#'+subId).html('');
			 var str = '<option value="">请选择...	</option>';	
			 $(regions).each(function(index, region) {
				 str += '<option value="' + region.regionId + '">' + region.localName + '</option>';
			 });
			 $('#'+subId).html(str);

		});
	}
	
	 
	
	
	function changeStr(obj){
		
		var str=$('#dl_province option:selected').text().trim()+'-'+
		$('#dl_city  option:selected').text().trim()+'-'+
		$('#dl_area option:selected').text().trim();
		$('#orderDelivery_shipArea').attr('value',str);
	
	}
	function changeCorpStr(obj,id){
		$("#"+id).attr("value",$(obj).find('option:selected').text().trim());
		 
		
	}
	
	
	
	
	
	
	
	
	$(document).ready(function() {
		var validator = $("#ship_form").validate( {
			errorElement : "div",
			errorClass : "x-vali-error",
			onfocusout : false,
			rules : {
				'goodsPackage.name' : "required",
				'goodsPackage.weight' : {
					required : true,
					number : true
				},
				'goodsPackage.packageDiscount' : {
					required : true,
					number : true
				},
				'goodsPackage.packageStore' : {
					required : true,
					number : true
				},
				'goodsPackage.description' : {
					required : true 
				},
				'goodsPackage.showOrder' : {
					required : true,
					number : true
				},
			},
			messages : {
				'goodsPackage.name' : "必填字段",
				'goodsPackage.weight' : {
					required : "必填字段",
					number : "请输入数字"
				},
				'goodsPackage.packageDiscount' : {
					required : "必填字段",
					number : "请输入数字"
				},
				'goodsPackage.packageStore' : {
					required : "必填字段",
					number : "请输入数字"
				},
				'goodsPackage.description' : {
					required : "必填字段" 
				},
				'goodsPackage.showOrder' : {
					required : "必填字段",
					number : "请输入数字"
				},
			},
			errorPlacement : function(error, element) {
				element.removeClass('x-vali-error');
				error.appendTo(element.parent());

			},

			success : function(div) {
				$(div).remove();
			}
		});
	});
</script>

	</body>
</html>